//
//  GeneralTool.m
//  DBAChain
//
//  Created by Mxionlly on 2018/9/10.
//  Copyright © 2018年 Evan. All rights reserved.
//

#import "GeneralTool.h"
#import "CommonData.h"

@implementation GeneralTool
#pragma mark - UIAlertAction
+ (void)showActionSheetWithTitle:(NSString *)title firstActionTitle:(NSString *)firstActionTitle secondActionTitle:(NSString *)secondActionTitle cancelActionTitle:(NSString *) cancelActionTitle  controller:(UIViewController *)controller actionBlock:(DWCompletionBlock)actionBlock  {
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
        
    }];
    [cancelAction setValue:[UIColor grayColor] forKey:@"titleTextColor"];
    
    UIAlertAction *firstAction = [UIAlertAction actionWithTitle:firstActionTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        if (actionBlock) {
            actionBlock(@1, nil);
        }
    }];
    [firstAction setValue:[UIColor blackColor] forKey:@"titleTextColor"];
    UIAlertAction *secondAction = [UIAlertAction actionWithTitle:secondActionTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        if (actionBlock) {
            actionBlock(@2, nil);
        }
    }];
    [secondAction setValue:[UIColor blackColor] forKey:@"titleTextColor"];
    
    [alertController addAction:firstAction];
    [alertController addAction:secondAction];
    [alertController addAction:cancelAction];
    if ((UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)) {
        UIPopoverPresentationController *popPresenter = [alertController popoverPresentationController];
        popPresenter.sourceView = controller.view;
        popPresenter.sourceRect = CGRectMake(0, KScreenHeight - 150,KScreenWidth , 150);
    }
    dispatch_async(dispatch_get_main_queue(), ^{
        [controller presentViewController:alertController animated:YES completion:nil];
    });
}
@end
